package lib.bone.admin.controller.system;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lib.bone.common.core.domain.ResponseDTO;
import lib.bone.system.domain.entity.SysUser;
import lib.bone.system.service.SysUserService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;

@Slf4j
@RestController
@RequestMapping("system")
@Api(tags = "管理员接口(上线需关闭)")
@AllArgsConstructor
public class SysAdminController {

    SysUserService userService;
    @PostMapping("admin/reset")
    @ApiOperation(value = "管理密码重置")
    public ResponseDTO<Object> adminPwdReset(@RequestParam("pwd") String pwd){
        Optional<SysUser> userOp = userService.findByUserName("super");
        if (userOp.isPresent()){
            SysUser user = userOp.get();
            user.setPassword(pwd);
            userService.updateOne(user);
        }
        return ResponseDTO.succMsg("重置成功");
    }
}
